﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CloudFranceTriple.Models;

namespace CloudFranceTriple.WebRole.Areas.Gaming.Controllers
{
    [CloudFranceTriple.WebRole.Filters.InitializeSimpleMembership]
    public class GameServerController : Controller
    {
        private cloudfrAboq2RsDMEntities db = new cloudfrAboq2RsDMEntities();

        //
        // GET: /Gaming/GameServer/

        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Index()
        {
            var gameserverset = db.GameServerSet.Include(g => g.GameSet).Include(g => g.LaBaffSet);
            return View(gameserverset.ToList());
        }

        //
        // GET: /Gaming/GameServer/Details/5

        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Details(int id = 0)
        {
            GameServerSet gameserverset = db.GameServerSet.Find(id);
            if (gameserverset == null)
            {
                return HttpNotFound();
            }
            return View(gameserverset);
        }

        //
        // GET: /Gaming/GameServer/Create

        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Create()
        {
            ViewBag.Game_Id = new SelectList(db.GameSet, "Id", "NameGame");
            ViewBag.LaBaff_Id = new SelectList(db.LaBaffSet, "Id", "LaBaffWebsite");
            return View();
        }

        //
        // POST: /Gaming/GameServer/Create

        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Create(GameServerSet gameserverset)
        {
            if (ModelState.IsValid)
            {
                db.GameServerSet.Add(gameserverset);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.Game_Id = new SelectList(db.GameSet, "Id", "NameGame", gameserverset.Game_Id);
            ViewBag.LaBaff_Id = new SelectList(db.LaBaffSet, "Id", "LaBaffWebsite", gameserverset.LaBaff_Id);
            return View(gameserverset);
        }

        //
        // GET: /Gaming/GameServer/Edit/5

        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Edit(int id = 0)
        {
            GameServerSet gameserverset = db.GameServerSet.Find(id);
            if (gameserverset == null)
            {
                return HttpNotFound();
            }
            ViewBag.Game_Id = new SelectList(db.GameSet, "Id", "NameGame", gameserverset.Game_Id);
            ViewBag.LaBaff_Id = new SelectList(db.LaBaffSet, "Id", "LaBaffWebsite", gameserverset.LaBaff_Id);
            return View(gameserverset);
        }

        //
        // POST: /Gaming/GameServer/Edit/5

        [HttpPost]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Edit(GameServerSet gameserverset)
        {
            if (ModelState.IsValid)
            {
                db.Entry(gameserverset).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            ViewBag.Game_Id = new SelectList(db.GameSet, "Id", "NameGame", gameserverset.Game_Id);
            ViewBag.LaBaff_Id = new SelectList(db.LaBaffSet, "Id", "LaBaffWebsite", gameserverset.LaBaff_Id);
            return View(gameserverset);
        }

        //
        // GET: /Gaming/GameServer/Delete/5

        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult Delete(int id = 0)
        {
            GameServerSet gameserverset = db.GameServerSet.Find(id);
            if (gameserverset == null)
            {
                return HttpNotFound();
            }
            return View(gameserverset);
        }

        //
        // POST: /Gaming/GameServer/Delete/5

        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        [Authorize(Roles = "RoleAdminGaming")]
        public ActionResult DeleteConfirmed(int id)
        {
            GameServerSet gameserverset = db.GameServerSet.Find(id);
            db.GameServerSet.Remove(gameserverset);
            db.SaveChanges();
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            db.Dispose();
            base.Dispose(disposing);
        }
    }
}